#@author     : Zhu Fei
#@date       : 2023-03-27
#@description: Top-level CMakeLists.txt for building Physika framework sample
#@version    : 1.0

cmake_minimum_required(VERSION 3.11.4)

project(test_gui)

FILE(GLOB SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)

set(TARGET_NAME test_gui)
add_executable(${TARGET_NAME} ${SRC_FILES})

target_include_directories(${TARGET_NAME} PRIVATE ${SRC_ROOT})
target_link_libraries(${TARGET_NAME} PRIVATE GlfwGUI)

if(WIN32)
    set_target_properties(${PROJECT_NAME} PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
elseif(UNIX)
    if (CMAKE_BUILD_TYPE MATCHES Debug)
        set_target_properties(${PROJECT_NAME} PROPERTIES
            RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/Debug")
    else()
        set_target_properties(${PROJECT_NAME} PROPERTIES
            RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/Release")
    endif()
endif()

#copy dependency dlls to target bin dir
if(MSVC)
    add_custom_command(TARGET ${TARGET_NAME}
                       POST_BUILD
                       # 'copy' command cannot be used here, because MSVC treats zero-value exit code as success, while unix-style 'copy' command
                       # treats 1-value exit code as success. I encountered this issue before and resolved it with MSVC settings, just don't know how to handle it
                       # in CMake. I failed with multiple tries, and complained about it to ChatGPT. He saved me with a solution. Amazing!
                       COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:physika_framework> $<TARGET_FILE_DIR:${TARGET_NAME}>
                       COMMAND_EXPAND_LISTS)
    install(FILES $<TARGET_FILE:physika_framework>
            DESTINATION ${TEST_INSTALL_PATH})
endif()

install(TARGETS ${TARGET_NAME}
        DESTINATION ${EXAMPLE_INSTALL_PATH})